﻿@model IEnumerable<QueXian.Models.Defect>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<form method="get" class="form-inline text-center" style="margin:10px">
    所属项目：@Html.DropDownList("DeviceID", null, new { @class = "form-control" })
    任务内容：<input type="text" name="content" class="form-control" placeholder="请输入内容关键字" />
    任务状态：<input type="radio" name="DefectState" value="2" id="r1"><label for="r1">已完成</label>
    <input type="radio" name="DefectState" value="1" id="r2"><label for="r2">未完成</label>
    <input type="radio" name="DefectState" value="0" checked="checked" id="r3"><label for="r3">全部</label>
    <input type="submit" value="查询" class="btn btn-primary" />
    @Html.ActionLink("添加", "Create", null, new { @class = "btn btn-primary" })
</form>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.DeviceID)
           
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DefectType)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DefectState)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DealTime)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
<tr>
    <td>
        @{
            if (item.DeviceID == 1)
            {
                @:电脑
            }
            else if (item.DeviceID == 2)
            {
                @:电话
            }
            else
            {
                @:打印机
            }
        }
    </td>
    <td>
        @{
            if (item.DefectType == 1)
            {
                @:紧急
            }
            else if (item.DefectType == 2)
            {
                @:重要
            }
            else
            {
                @:一般
            }
        }
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Content)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.AddTime)
    </td>
    <td>
        @(item.DefectState == 1?"未完成":"已完成")
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DealTime)
    </td>

    <td class="text-right">
        @if (item.DealTime == null)
        {
            <a href="#" data-des="@item.DefectID" class="btn btn-primary">完成任务</a>
        }
        <a href="#" data-del="@item.DefectID" class="btn btn-danger">删除</a>
    </td>
</tr>
    }

</table>
@section scripts{
    <script type="text/javascript">
        $(function(){
            $('a[data-del]').click(function () {
                var $this = $(this);
                var id = $this.attr("data-del");
                if (!confirm("are you sure?删除第" + id + "行")) return;
                $.post('@Url.Content("~/Default/Delete")', { id, id }, function (res) {
                    if (res == true) {

                        $this.closest("tr").remove();
                        alert("删除成功");
                    }
                })
            })
        })
        $(function () {
            $("a[data-des]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-des");
                $.post("@Url.Content("~/Default/Edit")", { id: id }, function (res) {
                    if (res==true) {
                        location.reload();
                        alert("完成任务!");
                    }
                })

            })

        })
    </script>


}